package mouse;

import impsoft.utils.ibot.RandomGenerator;
import impsoft.values.variable.MouseSettings;
import base.DreamScript;
import base.DreamUtility;

public class MouseSpeedHandler extends DreamUtility {

	public MouseSpeedHandler(DreamScript cs) {
		super(cs);
	}

	public void setMouseSpeedDefault() {
		setMouseSpeed(getDefaultSpeed());
	}

	public void setMouseSpeed(MouseSettings mouseSetting) {
		cs.getColorBot().currentSpeed = mouseSetting;
	}

	public static MouseSettings getDefaultSpeed() {
		return new MouseSettings() {
			@Override
			public double getSpeed(int distance) {
				if (distance > 300) {
					return RandomGenerator.randomNormalDouble(0.5D, 1.5D);
				} else if (distance > 150) {
					return RandomGenerator.randomNormalDouble(1.0D, 2.3D);
				} else {
					return RandomGenerator.randomNormalDouble(2.8D, 4.5D);
				}
			}
		};
	}

	public static MouseSettings boostMouse(final double percent) {
		MouseSettings mouseSettings = new MouseSettings() {
			@Override
			public double getSpeed(int distance) {
				double value = 0;
				if (distance > 300) {
					value = RandomGenerator.randomNormalDouble(0.5D, 1.5D);
					return value - value * percent / 100D;
				} else if (distance > 150) {
					value = RandomGenerator.randomNormalDouble(1.0D, 2.3D);
					return value - value * percent / 100D;
				} else {
					value = RandomGenerator.randomNormalDouble(2.8D, 4.5D);
					return value - value * percent / 100D;
				}
			}
		};
		return mouseSettings;
	}

	public static MouseSettings reduceMouse(final double percent) {
		MouseSettings mouseSettings = new MouseSettings() {
			@Override
			public double getSpeed(int distance) {
				double value = 0;
				if (distance > 300) {
					value = RandomGenerator.randomNormalDouble(0.5D, 1.5D);
					return value + value * percent / 100D;
				} else if (distance > 150) {
					value = RandomGenerator.randomNormalDouble(1.0D, 2.3D);
					return value + value * percent / 100D;
				} else {
					value = RandomGenerator.randomNormalDouble(2.8D, 4.5D);
					return value + value * percent / 100D;
				}
			}
		};
		return mouseSettings;
	}

	public static MouseSettings instantClick() {
		MouseSettings mouseSettings = new MouseSettings() {
			@Override
			public double getSpeed(int distance) {
				return 0D;
			}
		};
		return mouseSettings;
	}
}